import { BaseWindow } from "../../../component/window/BaseWindow";
import { Language } from "../../../../extend/language/Language";
import { DataEvent } from "../../events/DataEvent";
import { LGXBDescTopWin } from "./win/LGXBDescTopWin";
import { LGXBDescRightWin } from "./win/LGXBDescRightWin";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { ObjCreate } from "../common/ObjCreate";
import { ImagesConst } from "../../resource/ImagesConst";
import { ZhuanPanViewerObject } from "./zhuanpan/ZhuanPanViewerObject";
import { DiceBtn } from "./startDiceBtn/DiceBtn";
import { LGXBDice } from "./dice/LGXBDice";
import { TaskIsOnPlayer } from "./TaskIsOnPlayer";
import { GCheckBox } from "../../../../com/mui/controls/GCheckBox";
import { Cache } from "../../cache/Cache";
import { Global } from "../../../../com/gengine/global/Global";
import { MsgManager } from "../../manager/MsgManager";
import { HtmlDebugUtils } from "./HtmlDebugUtils";
import { EventName } from "../../mvc/EventName";
import { LGXBViewHanderType } from "./LGXBViewHanderType";
import { LGXBConfig } from "../../resource/LGXBConfig";
import { LGXBMap } from "./map/LGXBMap";
import { RewardItem } from "./map/RewardItem";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { NpcEffectRule } from "../../rules/NpcEffectRule";
import { RolePlayerCopy } from "./player/RolePlayerCopy";
import { GameProxy } from "../../mvc/GameProxy";
import { LGXBData } from "./data/LGXBData";
type int = number;
//class LGXBModule
    
    export  class LGXBModule extends BaseWindow
    {
        constructor()
        {
            super();
            setSize(920, 527);
            this.titleHeight = 25;
            this.title = Language.getString(80287);
            return;
        }

        /* internal  */zhuanPanCloseHander(arg1: DataEvent): void
        {
            this._zhuanPan.hide();
            this._player.continueMoveToSide(arg1.data as int);
            return;
        }

        protected /* override */ createChildren(): void
        {
            super.createChildren();
            this._winTop = new LGXBDescTopWin();
            this._winTop.x = 17;
            this._winTop.y = 36;
            this.addChild(this._winTop);
            this._winRight = new LGXBDescRightWin();
            this._winRight.x = 718;
            this._winRight.y = 36;
            this.addChild(this._winRight);
            Dispatcher.addEventListener("#CoinIsNotEnough#", this.coinIsNotEnoughHander);
            this.gameBodyBox = new Object /* flash.display.Sprite */();
            ObjCreate.setObjAttri(this.gameBodyBox, 17, 168, -1, -1, this);
            ObjCreate.createBg(0, 0, 699, 348, this.gameBodyBox, ImagesConst.WindowCenterB);
            ObjCreate.createBitmap(ImagesConst.LGXB_bg, 1, 1, this.gameBodyBox);
            var loc1=ObjCreate.createCheckBox(Language.getString(85022), 575, 322, 100, 28, this.gameBodyBox, "GCheckBoxYellow");
            loc1.addEventListener(flash.events.Event.CHANGE, this.checkAnimateHander);
            this.autoFinishTaskCheckbox = ObjCreate.createCheckBox(Language.getString(85024), 325, 322, 240, 28, this.gameBodyBox, "GCheckBoxYellow");
            this.autoFinishTaskCheckbox.addEventListener(flash.events.Event.CHANGE, this.autoFinishTaskHander);
            this.initRewardMap();
            this.createPlayer();
            this._zhuanPan = new ZhuanPanViewerObject(this.gameBodyBox);
            this._zhuanPan.addEventListener("#stopRotate#", this.zhuanPanCloseHander);
            this._diceBtn = new DiceBtn();
            ObjCreate.setObjAttri(this._diceBtn, 300, 195, -1, -1, this.gameBodyBox);
            this._diceBtn.toShow();
            this._diceBtn.addEventListener(flash.events.MouseEvent.CLICK, this.diceStartPlayHander);
            this._dices = new LGXBDice();
            this._dices.endPlayFunction = this.endPlay;
            ObjCreate.setObjAttri(this._dices, 345, 300, -1, -1, this.gameBodyBox);
            this._taskIsOnPlayer = new TaskIsOnPlayer();
            this.dispatchEvent(new Object /* flash.events.Event */("#initFinish#"));
            return;
        }

        /* internal  */autoFinishTaskHander(arg1: Object /* flash.events.Event */): void
        {
            this._winRight.checkboxIsSelected = this.autoFinishTaskCheckbox.selected;
            this._winRight.checkQuickComplete();
            return;
        }

        /* internal  */coinIsNotEnoughHander(arg1: Object /* flash.events.Event */): void
        {
            this.autoFinishTaskCheckbox.selected = false;
            this._winRight.checkboxIsSelected = false;
            return;
        }

        /* internal  */checkAnimateHander(arg1: Object /* flash.events.Event */): void
        {
            this._jumpAnimate = GCheckBox(arg1.currentTarget).selected;
            this._zhuanPan.jumpAnimate = this._jumpAnimate;
            this._dices.jumpAnimate = this._jumpAnimate;
            this._player.jumpAnimate = this._jumpAnimate;
            return;
        }

        /* internal  */diceStartPlayHander(arg1: Object /* flash.events.Event */): void
        {
            if (Cache.instance.lgxb.dicCountInfo.count <= 0 && !Global.isDebugModle) 
            {
                MsgManager.showRollTipsMsg(Language.getString(60027));
            }
            else 
            {
                this._diceBtn.toHide();
                HtmlDebugUtils.htmlTrace("role current position is :(" + this._player.currentPoint.x + "," + this._player.currentPoint.y + ")");
                Dispatcher.dispatchEvent(new Object /* flash.events.Event */(EventName.LGXBtoGetRoads));
            }
            return;
        }

        /* internal  */checkSideHander(arg1: DataEvent): void
        {
            this.viewerHander(null, LGXBViewHanderType.showZhuanPan, arg1.data as Array<any>);
            return;
        }

        /* internal  */initRewardMap(): void
        {
            var loc5=NaN;
            var loc6=null;
            var loc7=null;
            var loc8=0;
            var loc9=0;
            var loc10=null;
            var loc11=null;
            var loc12=null;
            var loc1=LGXBConfig.instance.map;
            var loc2=LGXBMap.instance.offx;
            var loc3=LGXBMap.instance.offy;
            var loc4=LGXBMap.instance.grid_w + LGXBMap.instance.gridblank_w;
            loc5 = LGXBMap.instance.grid_h + LGXBMap.instance.gridblank_h;
            var loc13=0;
            var loc14=loc1;
            for(loc6 of loc14) 
            {
                (loc10 = new RewardItem()).eventType = loc6.randEvent;
                loc10.x = loc2 + loc6.y * loc4;
                loc10.y = loc3 + loc6.x * loc5;
                this.gameBodyBox.addChild(loc10);
            }
            loc8 = (loc7 = LGXBMap.instance.getThreeRoads()).length;
            loc9 = 0;
            while (loc9 < loc8) 
            {
                loc11 = loc7[loc9];
                loc12 = GlobalClass.getBitmap(ImagesConst.LGXB_RoadHint);
                ObjCreate.setObjAttri(loc12, int(loc11.x - loc4 / 2 + 5), int(loc11.y + loc5 / 2 - loc12.height - 5), -1, -1, this.gameBodyBox);
                ++loc9;
            }
            return;
        }

        public /* override */ hide(): void
        {
            super.hide();
            this._player.removeToStage(this, false);
            return;
        }

        public /* override */ show(arg1: int=0, arg2: int=0): void
        {
            super.show(arg1, arg2);
            this._player.addToStage(this);
            NpcEffectRule.registDialogEffectWindow(this);
            return;
        }

        /* internal  */endPlay(): void
        {
            this._player.gotoPath(this.targetMovePath);
            this._dices.hide(true);
            return;
        }

        /* internal  */createPlayer(): void
        {
            this._player = new RolePlayerCopy();
            this._player.updateEquitment();
            this.gameBodyBox.addChild(this._player);
            this._player.addEventListener("#stopMove#", this.stopMoveHander);
            this._player.addEventListener("#toCheckSide#", this.checkSideHander);
            return;
        }

        /* internal  */stopMoveHander(arg1: Object /* flash.events.Event */): void
        {
            if (this._player.hasFinishSteps) 
            {
                GameProxy.lgxb.personOnReach();
            }
            return;
        }

        public viewerHander(arg1: Object /* flash.events.Event */=null, arg2: string=null, arg3: Array<any>=null): void
        {
            var loc1=null;
            var loc2=0;
            var loc3=null;
            var loc4=0;
            var loc5=0;
            var loc6=false;
            var loc7=null;
            var loc8=null;
            var loc9=null;
            if (arg1) 
            {
                arg2 = arg1.type;
            }
            var loc10=arg2;
            switch (loc10) 
            {
                case LGXBViewHanderType.showDiceStarBtn:
                {
                    this._dices.hide(false);
                    this._diceBtn.toShow();
                    break;
                }
                case LGXBViewHanderType.gameInit:
                {
                    loc1 = Cache.instance.lgxb.loginInfo;
                    this._player.setPosition(loc1.x, loc1.y, false, loc1.dir);
                    this._dices.hide(false);
                    break;
                }
                case LGXBViewHanderType.playerToTargetPoints:
                {
                    this.targetMovePath = LGXBData.instance.getPath(arg3, this._player);
                    if (this.targetMovePath != null) 
                    {
                        this._dices.show();
                        this._dices.diceData = [this.targetMovePath.length];
                        this._dices.startPlay();
                    }
                    else 
                    {
                        MsgManager.showRollTipsMsg(Language.getString(60027));
                        this._diceBtn.toShow();
                    }
                    break;
                }
                case LGXBViewHanderType.updateTopDescWin:
                {
                    loc2 = arg3[0];
                    loc3 = arg3[1];
                    loc4 = arg3[2];
                    loc5 = arg3[3];
                    this._winTop.updateWin(loc2, loc3, loc4, loc5);
                    break;
                }
                case LGXBViewHanderType.updateRightDescWin:
                {
                    loc6 = arg3[0];
                    loc7 = arg3[1];
                    loc8 = arg3[2];
                    loc9 = arg3[3];
                    this._winRight.updateWin(loc6, loc7, loc8, loc9);
                    break;
                }
                case LGXBViewHanderType.showZhuanPan:
                {
                    this._zhuanPan.show(arg3[0], arg3[1]);
                    this._dices.hide(true);
                    this._diceBtn.toHide();
                    break;
                }
                case LGXBViewHanderType.taskIsOn:
                {
                    this._diceBtn.visible = false;
                    this._diceBtn.toHide();
                    this._taskIsOnPlayer.toShow(this.gameBodyBox);
                    break;
                }
                case LGXBViewHanderType.taskIsFinish:
                {
                    this._diceBtn.visible = true;
                    this._diceBtn.toShow();
                    this._taskIsOnPlayer.toHide();
                    break;
                }
                case LGXBViewHanderType.playerEquipChange:
                {
                    this._player.updateEquitment();
                    break;
                }
            }
            return;
        }

        /* internal */ /* var */targetMovePath: Array<any>;

        public /* var */_player: RolePlayerCopy;

        /* internal */ /* var */_zhuanPan: ZhuanPanViewerObject;

        /* internal */ /* var */_dices: LGXBDice;

        /* internal */ /* var */gameBodyBox: Object /* flash.display.Sprite */;

        /* internal */ /* var */_diceBtn: DiceBtn;

        /* internal */ /* var */_taskIsOnPlayer: TaskIsOnPlayer;

        /* internal */ /* var */_winTop: LGXBDescTopWin;

        /* internal */ /* var */_winRight: LGXBDescRightWin;

        /* internal */ /* var */_jumpAnimate: Boolean=false;

        /* internal */ /* var */autoFinishTaskCheckbox: GCheckBox;
    }
